﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class News_DownLoadList : System.Web.UI.Page
{
    string type = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["type"] == null)
            {
                type = "notype";
            }
            else
            {
                type = Request.QueryString["type"].ToString().Trim();
            }
            Repeaterdatabind();
            SetDatePicker();
        }
    }

    //设置日期选择框的属性
    protected void SetDatePicker()
    {
        txtTime1.Attributes.Add("onfocus", "WdatePicker({maxDate:'#F{$dp.$D(\\'" + txtTime2.ClientID + "\\')||\\'2120-10-01\\'}'})");
        txtTime2.Attributes.Add("onfocus", "WdatePicker({minDate:'#F{$dp.$D(\\'" + txtTime1.ClientID + "\\')}',maxDate:'2120-10-01'})");
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Repeaterdatabind();
    }
    protected void Repeaterdatabind()
    {
        StringBuilder Sqlstr = new StringBuilder();
        DataTable dt = new DataTable();
        string strtype = string.Empty;
        Sqlstr.Append("select * from Sys_Attached where 1=1");
        if (txtTopic.Text.Trim() != "")
        {
            Sqlstr.AppendFormat(" and filename like '%{0}%'",txtTopic.Text.Trim());
        }
        if (ddlType.SelectedValue != "")
        {
            Sqlstr.AppendFormat(" and filetype='{0}'", ddlType.SelectedValue.ToString());
        }
        if (txtTime1.Value.Trim() != "" && txtTime2.Value.Trim() != "")
        {
            Sqlstr.Append(" and createdate between '" + txtTime1.Value.Trim() + "' and '" + txtTime2.Value.Trim() + "'");
        }
        switch (type)
        {
            case "txt":
                Sqlstr.Append(" and filetype='文档'");
                break;
            case "table":
                Sqlstr.Append(" and filetype='表格'");
                break;
            case "others":
                Sqlstr.Append(" and filetype='其他'");
                break;
            case "文档":
                Sqlstr.Append(" and filetype='文档'");
                break;
            case "表格":
                Sqlstr.Append(" and filetype='表格'");
                break;
            case "其他":
                Sqlstr.Append(" and filetype='其他'");
                break;
            default:
                break;
        }
        Sqlstr.Append(" order by createdate desc");
        dt=PM.Code.DAL.DbHelper.GetPagedDataTable(Sqlstr.ToString(),50,AspNetPager1);
        Repeater1.DataSource=dt;
        Repeater1.DataBind();
    }



    //截取多余字符并高亮显示需要高亮的标题
    static public string strTrim(string str)
    {
        string tmpStr;
        tmpStr = PM.Code.Basic.pmbasic.strCal(str, 60);
        return tmpStr;
    }
    //将数据库中的长时间转变成短时间
    static public string ToShortTime(string time)
    {
        string date;
        date = (Convert.ToDateTime(time)).ToShortDateString();
        return date;
    }
    //搜索
    protected void btnSeach_Click(object sender, ImageClickEventArgs e)
    {
        Repeaterdatabind();
    }
}
